/*
 * @Author: LiaoWeiLin
 * @Date: 2019-06-19 17:01:04
 * @Last Modified by: LiaoWeiLin
 * @Last Modified time: 2019-07-16 18:13:42
 */

import wepy from 'wepy';
import tip from './tip';

const API_DOP = "https://king.tongdao.ink/";

const API_DEV = "https://test.tongdao.ink/";  // 192.168.0.124:8080

const request = async(params = {}, url) => {
  let loading =  params['loading'];
  if(loading != false) tip.loading();
  let method = params['method'] || 'POST';
  let data = params['data'] || '';
  let res =  await wepy.request({
    url: API_DOP + url,
    method: method,
    data: data,
    header: {
      // 'Content-Type': 'application/json'
      'content-type': 'application/x-www-form-urlencoded'
    }
  })
  if(res.data.code == 0) {
    tip.error('网络出错,请稍后重试!')
  }
  tip.loaded();
  return res.data
}

module.exports = {
  request
}
